/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package treegenerator;

import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.renderer.RenderManager;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import org.netbeans.api.project.Project;

import org.openide.awt.ActionRegistration;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionID;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.NbBundle.Messages;
import treegenerator.gui.MainPanel;

@ActionID(category = "File",
id = "treegenerator.CreateTreeAction")
@ActionRegistration(iconBase = "treegenerator/TreeGen.png",
displayName = "#CTL_CreateTreeAction")
@ActionReferences({
    @ActionReference(path = "Menu/File", position = 1406)
})
@Messages("CTL_CreateTreeAction=Create Tree")
public final class CreateTreeAction implements ActionListener {

    private final Project context;
    private final ProjectAssetManager assetManager;    

    public CreateTreeAction(Project context) {
        this.context = context;
        assetManager = context.getLookup().lookup(ProjectAssetManager.class);       
        
    }

    public void actionPerformed(ActionEvent ev) {        
        FileObject fo = context.getProjectDirectory(); 
        RenderManager renderManager = SceneApplication.getApplication().getRenderManager();        
        JFrame frame = new JFrame("Tree generator");        
        final MainPanel mp = new MainPanel(FileUtil.toFile(fo),assetManager,renderManager);        
        frame.setContentPane(mp);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);        
        frame.addWindowListener(new WindowAdapter(){
            @Override
            public void windowClosed(WindowEvent e) {
                mp.dispose();
            }
        });
        frame.setSize(1000,900);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);              
    }
}
